part of '../widget.dart';

class _SymbolButton extends StatelessWidget {
  const _SymbolButton({
    required this.symbol,
    required this.count,
    required this.size,
    required this.onPressed,
  });

  final String symbol;
  final int count;
  final double size;
  final VoidCallback? onPressed;

  Widget _buildSymbol({
    required BuildContext context,
  }) {
    return ClipOval(
      child: Container(
        color: HomeCoreTheme.of(context).cardButtonColor,
        width: double.infinity,
        height: double.infinity,
        child: Center(
          child: Text(
            symbol,
            style: HomeCoreTheme.of(context).textTheme.cardButton.copyWith(
                  fontSize: size / 2.2,
                ),
          ),
        ),
      ),
    );
  }

  Widget _buildCounter({
    required BuildContext context,
  }) {
    return ClipOval(
      child: Container(
        color: HomeCoreTheme.of(context).cardColor,
        child: Padding(
          padding: EdgeInsets.all(size / 40),
          child: ClipOval(
            child: Container(
              color: HomeCoreTheme.of(context).cardButtonColor,
              width: size / 3.2,
              height: size / 3.2,
              child: Center(
                child: Text(
                  '$count',
                  style: HomeCoreTheme.of(context).textTheme.cardButton.copyWith(
                        fontSize: size / 6,
                      ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Opacity(
      opacity: onPressed == null ? 0.4 : 1.0,
      child: AppButton(
        borderRadius: BorderRadius.circular(100),
        onPressed: onPressed,
        child: SizedBox(
          height: size,
          width: size,
          child: Stack(
            children: [
              _buildSymbol(
                context: context,
              ),
              if (count > 1)
                Positioned.fill(
                  child: Align(
                    alignment: Alignment.topRight,
                    child: _buildCounter(
                      context: context,
                    ),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
